<?php

class m110923_023135_merchant extends CDbMigration {
	public function safeUp() {
		$this
			->createTable('erp_merchant',
				array(
					'id' => 'pk',
					'name' => 'string',
					'address' => 'string',
					'phone' => 'string',
					'fax' => 'string',
					'otherName' => 'string',
					'bossName' => 'string',
					'bossPhone' => 'string',
					'contactName' => 'string',
					'contactPhone' => 'string',
					'serviceScope' => 'string',
					'note' => 'string',
					'createTime' => 'datetime',
					'createUserId' => 'int',
					'updateTime' => 'datetime',
					'updateUserId' => 'int',
				));
		$this->createIndex("merchant_create_user_id", 'erp_merchant', 'createUserId');
		$this
			->addForeignKey('fk_merchant_create_user_id', 'erp_merchant', 'createUserId',
				'erp_user', 'id', 'SET NULL', 'CASCADE');
		$this->createIndex("merchant_update_user_id", 'erp_merchant', 'updateUserId');
		$this
			->addForeignKey('fk_merchant_update_user_id', 'erp_merchant', 'updateUserId',
				'erp_user', 'id', 'SET NULL', 'CASCADE');
	}

	public function safeDown() {
		$this->dropTable('erp_merchant');
	}
}
